<?php
use yii\helpers\Url;
use yii\web\View;
use app\assets\NewCreativeAsset;
NewCreativeAsset::register($this);
$this->title = \Yii::t('solution', 'New Creative');
$jsMsgs = $this->context->loadJsMsgs([
  'creativeForm'
]);
$this->registerJs("VAM.setVar('LANGUAGE_JS', '".$jsMsgs."');", View::POS_HEAD);
?>
<style>
  html,body{background-color: #fff;} 
</style>
<div class="panel mb0">
  <div class="panel-heading">
  </div>
  <div class="panel-body">
    <div class="row">
      <div class="col-sm-8 col-sm-offset-2">
        <form class="form-horizontal" id="data-frm" method="POST" action="<?php echo Url::to(['creative/new-mobile-app-creative-handle']);?>">
      <input class="hidden" type="text" name="solution_id" value="<?=$solutionId?>">
          <input class="hidden" type="text" name="id" value="">
          <fieldset>
            <legend><?=\Yii::t('solution', 'Creative Info')?></legend>
            <div class="form-group">
              <label class="col-sm-3 control-label" for="creative_name" >
                <em>*</em>
                <?=\Yii::t('solution', 'Creative Name')?>：
              </label>
              <div class="col-sm-7">
                <input class="form-control" id="creative_name" type="text" name="name" value="" placeholder="<?=\Yii::t('creative', 'Creative Name')?>">
                <div class="help-block text-error" id="creative_name_err"></div>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-3 control-label" for="advertiser_name" >
                <?=\Yii::t('solution', 'Advertiser')?>：
              </label>
              <div class="col-sm-7">
                <input class="form-control" id="advertiser_name" type="text" name="advertiser_name" value="" placeholder="<?=\Yii::t('creative', 'Advertiser')?>">
                <div class="help-block text-error" id="advertiser_name_err"></div>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-3 control-label" for="creative_vocation_large" >
                <em>*</em>
                <?=\Yii::t('solution', 'Vocation')?>：
              </label>
              <div class="col-sm-3">
                <select class="form-control" id="creative_vocation_large" name="parent_category">
                </select>
              </div>
              <div class="col-md-3">
                <select class="form-control" id="creative_vocation_small" name="category">
                </select>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-3 control-label" for="landing_page_url">
                <em>*</em>
                <?=\Yii::t('solution', 'Target Url')?>：
              </label>
              <div class="col-sm-7">
                <input class="form-control" id="landing_page_url" type="text" name="landing_page" value="" placeholder="http(s)://">
                <div class="help-block text-error" id="landing_page_url_err"></div>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-3 control-label" for="audit_target_url">
                <?=\Yii::t('solution', 'Audit Url')?>：
              </label>
              <div class="col-sm-7">
                <input class="form-control" id="audit_target_url" type="text" name="adomain" value="" placeholder="http(s)://">
                <div class="help-block text-error" id="audit_target_url_err"></div>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-3 control-label" for="impr_monitor_url">
                <?=\Yii::t('solution', 'Show Url')?>：
              </label>
              <div class="col-sm-7">
                <input class="form-control" id="impr_monitor_url" type="text" name="show_monitor_url" value="" placeholder="http(s)://">
                <div class="help-block text-error" id="impr_monitor_url_err"></div>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-3 control-label" for="click_monitor_url" >
                <?=\Yii::t('solution', 'Click Url')?>：
              </label>
              <div class="col-sm-7">
                <input class="form-control" id="click_monitor_url" type="text" name="click_monitor_url" value="" placeholder="http(s)://">
                <div class="help-block text-error" id="click_monitor_url_err"></div>
              </div>
            </div>  
            <div class="form-group">
              <label for="creative_type" class="col-sm-3 control-label">
                <?=\Yii::t('solution', 'Type')?>：
              </label>
              <div class="col-sm-7">
                <select class="form-control" id="creative_type" name="ad_type">
                  <!--<option value="0"><?=\Yii::t('solution', 'Banner')?></option>-->
                  <!--<option value="2"><?=\Yii::t('solution', 'Interstitial')?></option>-->
                  <option value="3"><?=\Yii::t('solution', 'Feeds')?></option>
                  <option value="1"><?=\Yii::t('solution', 'App Splash')?></option>
                </select>
              </div>
            </div>
            <div id="feeds-sub-type-wrapper" class='vam-hidden'>
              <div class="form-group">
                <label class="col-sm-3 control-label"></label>
                <div class="col-sm-7">
                  <!-- <label class="radio-inline">
                    <input type="radio" name="feeds_sub_type" value="0" checked>默认
                  </label> -->
                  <label class="radio-inline">
                    <input type="radio" name="feeds_sub_type" value="1" checked>图文
                  </label>
                  <label class="radio-inline">
                    <input type="radio" name="feeds_sub_type" value="2">大图
                  </label>
                  <label class="radio-inline">
                    <input type="radio" name="feeds_sub_type" value="3">三图
                  </label>
                </div>
              </div>
            </div>   
            <div class="form-group">
              <label for="creative_title" class="col-sm-3 control-label"  id="creative_title_label">
                <?=\Yii::t('solution', 'Title')?>：
              </label>
              <div class="col-sm-7">
                <input class="form-control" id="creative_title" name="title" data-err="creative_title_err" type="text" value="">
                <div class="help-block text-error" id="creative_title_err"></div>
              </div>
            </div>
            <div class="form-group">
              <label for="creative_description" class="col-sm-3 control-label">
                <?=\Yii::t('solution', 'Description')?>：
              </label>
              <div class="col-sm-7">
                 <input class="form-control" id="creative_description" data-err="creative_description_err" name="txt" type="text" value="">
                 <div class="help-block text-error" id="creative_description_err"></div>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-3 control-label" for="alternative_creative_size">
                <?=\Yii::t('solution', 'Valid Size')?>：
              </label>
              <div class="col-sm-7">
                <p class="form-control-static" id="alternative_creative_size" name="alternative_creative_size"><?php 
        $sizeList = [];
        foreach ($sizes as $k => $size) {
          $sizeList[] = $size['width'].'*'.$size['height'];
        }
        $sizeList = array_unique($sizeList);
        sort($sizeList);
        foreach ($sizeList as $k => $size) {
          if ($k < 1) {
            echo '<span class="size-item">'.$size.'</span>';
          } else if($k >= 1 && $k < 10) {
            echo '<span class="size-item">, '.$size.'</span>';
          } else {
            echo '<span class="size-item vam-hidden">, '.$size.'</span>';
          }
        }
        if (count($sizeList) > 10) {
          echo '<button title="'.Yii::t('creative', 'More').'" class="btn btn-link btn-xs view-more-size">'.Yii::t('creative', 'More').'</button>';
        }
        ?></p>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-3 control-label" for="alternative_creative_size">
                <?=\Yii::t('solution', 'Valid Material Type')?>：
              </label>
              <div class="col-sm-7">
                <p class="form-control-static" id="alternative_creative_size" name="alternative_creative_size">
                <?php
                    $tt = ['JPG, PNG'];
                    if (in_array(1, $formats)) $tt[] = 'JPG, PNG';
                    if (in_array(2, $formats)) $tt[] = 'GIF';
                    if (in_array(3, $formats)) $tt[] = 'SWF';
                    if (in_array(4, $formats)) $tt[] = 'TXT';
                    if (in_array(5, $formats)) $tt[] = 'FLV';
                    if (in_array(5, $formats)) $tt[] = 'MP4';
                    $tt = array_unique($tt);
                    echo implode(', ', $tt);
                ?>
                </p>
              </div>
            </div>
            <div class="form-group" id="material_source">
              <label class="col-sm-3 control-label" for="alternative_creative_size">
                <?=\Yii::t('creative', 'Material Source')?>：
              </label>
              <div class="col-sm-7">
                <label class="radio-inline">
                  <input type="radio" name="material_source" value="0" checked><?=\Yii::t('creative', 'Upload Material')?>
                </label>
                <label class="radio-inline">
                  <input type="radio" name="material_source" value="1"><?=\Yii::t('creative', 'Custom Url')?>
                </label>
              </div>
            </div>
            <div id="custom_material_url">
              <div class="custom-material-url">
                <div class="form-group">
                  <label for="custom-url" class="control-label col-sm-3 required">
                    <em>*</em>
                    <?=\Yii::t('creative', 'Material Url')?>：
                  </label>
                  <div class="col-sm-7">
                    <input type="text" id="" class="form-control custom-url" name="custom_url[]" value="" data-err="custom-url-err">
                    <div class="help-block text-error custom-url-err"></div>
                  </div>
                  <a class="btn btn-link add-material-url" title="<?=\Yii::t('creative', 'Click to add material url')?>" data-type="custom-material-url">
                    <i class="fa fa-plus-circle"></i>
                  </a>
                </div>
                <div class="form-group custom-adsize">
                  <label class="control-label col-md-3 required">
                    <em>*</em>
                    <?=\Yii::t('creative', 'Material Size')?>：
                  </label>
                  <label class="control-label col-md-1 required pr0">
                    <em>*</em>
                    <?=\Yii::t('creative', 'Width')?>：
                  </label>
                  <div class="col-md-2">
                    <input class="form-control adspace-width" type="text" value="" name="width[]" data-err="width-err">
                    <div class="help-block text-error width-err"></div>
                  </div>
                  <label class="control-label col-md-1 required pr0">
                    <em>*</em>
                    <?=\Yii::t('creative', 'Height')?>：
                  </label>
                  <div class="col-md-2">
                    <input class="form-control adspace-height" type="text" value="" name="height[]" data-err="height-err">
                    <div class="help-block text-error height-err"></div>
                  </div>
                </div>
                <div class="form-group">
                  <label for="material-type" class="col-md-3 control-label required">
                    <em>*</em>
                    <?=\Yii::t('creative', 'Material Type')?>：
                  </label>
                  <div class="col-md-7">
                    <select name="material_type[]" id="" class="form-control">
                      <option value="JPG">JPG</option>
                      <option value="PNG">PNG</option>
                    </select>
                  </div>
                </div>
              </div>
            </div>
            <div id="local_upload_material">
              <div class="form-group" id="material_hero_choice">
                <label class="col-sm-3 control-label" for="alternative_creative_hero_choice">
                <?=\Yii::t('creative', 'For Hero App')?>：
                </label>
                <div class="col-sm-7">
                <label class="radio-inline">
                  <input type="radio" name="hero_app" value="0" checked>否
                </label>
                <label class="radio-inline">
                  <input type="radio" name="hero_app" value="1">是
                </label>
                </div>
              </div>
			  <div class="form-group" id="material_protocal">
				  <label class="col-sm-3 control-label" for="alternative_creative_size">
					<?=\Yii::t('creative', 'Material Protocal')?>：
				  </label>
				  <div class="col-sm-7">
					<label class="radio-inline">
					  <input type="radio" name="protocal" value="1" checked>HTTP
					</label>
					<label class="radio-inline">
					  <input type="radio" name="protocal" value="2">HTTPS
					</label>
				  </div>
			  </div>
              <div class="form-group">
                <label class="col-sm-3 control-label required" id="upload_material_label" for="upload_material">
                <?=\Yii::t('solution', 'Upload Material')?>：
              </label>
              <div class="col-sm-2 col-sm-offset-6">
                <button class="btn btn-info" id="upload-material" type="button">
                  <i class="fa fa-upload"></i>
                  <?=\Yii::t('solution', 'Upload')?>
                </button>
              </div>
              <div class="col-sm-12 mt10 text-center">
                <div class="creative-preview-wrap">
                </div>
                <img class="img-thumbnail creative_material_default" id="creative_material_default" data-src="holder.js/310x260/text:<?=\Yii::t('solution', 'Not upload')?>" alt="<?=\Yii::t('solution', 'Not upload')?>">
                <input id="upload_material" data-err="upload_material_err" type="hidden" value="">
                <div class="help-block text-error" id="upload_material_err"></div>
              </div>
            </div>
          </fieldset>
          <fieldset>
            <div class="form-group">
              <div class="col-sm-offset-3 col-sm-7">
                <div class="btn-form-group pull-right">
                  <input class="operate-type" type="hidden" name="operate_type" value="save">
                  <button type="submit" class="btn btn-primary" data-loading-text="<i class='fa fa-spinner fa-spin'></i> <?=\Yii::t('common', 'Saving')?>..."><?=\Yii::t('common', 'Save')?></button>
<!--                   <a href="<?php echo Url::to(['creative/index']); ?>" class="btn btn-default"><?=\Yii::t('common', 'Back')?></a> -->
                </div>
              </div>
            </div>
          </fieldset>
        </form>
      </div>
    </div>
  </div>
</div>
<div class="modal fade" id="upload-material-modal">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        <h4 class="modal-title"><?=\Yii::t('solution', 'Upload Material')?></h4>
      </div>
      <div class="modal-body">
        <div class="portlet-content">
          <span class="btn btn-success btn-sm fileinput-button">
            <i class="fa fa-plus"></i>
            <span><?=\Yii::t('solution', 'File')?></span>
            <input id="creative-id" type="hidden" name="creative_id" value="${id}" >
            <!-- The file input field used as target for the file upload widget -->
            <input type="file" multiple="" name="files[]" id="fileupload">
          </span>
          <br>
          <br>
          <!-- The global progress bar -->
          <div class="progress" id="progress">
              <div aria-valuemax="100" aria-valuemin="0" class="progress-bar progress-bar-success progress-bar-striped">0%</div>
          </div>
          <!-- The container for the uploaded files -->
          <div class="files" id="files">
            <table class="table table-striped table-bordered upload-info">
              <thead>
                <tr>
                  <th>ID</th>
                  <th><?=\Yii::t('solution', 'File Name')?></th>
                  <th><?=\Yii::t('solution', 'File Size')?>(KB)</th>
                  <th><?=\Yii::t('solution', 'Upload Time')?></th>
                  <th><?=\Yii::t('solution', 'Info')?></th>
                  <th><?=\Yii::t('solution', 'Uploader')?></th>
                </tr>
              </thead>
              <tbody></tbody>
              </table>
            </div>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal"><?=\Yii::t('common', 'Close')?></button>
        <button type="button" class="btn btn-primary" id="upload-confirm-operate" data-material-id=""><?=\Yii::t('common', 'Sure')?></button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!-- Custom Material Url -->
<div class="custom-material-url new-custom-url hidden">
  <div class="form-group">
    <label for="custom-url" class="control-label col-sm-3">
      <?=\Yii::t('creative', 'Material Url')?>：
    </label>
    <div class="col-sm-7">
      <input type="text" id="" class="form-control custom-url" name="custom_url[]" value="" data-err="custom-url-err">
      <div class="help-block text-error custom-url-err"></div>
    </div>
    <a class="btn btn-link del-operate" title="<?=\Yii::t('creative', 'Click to delete material url')?>" data-type="custom-material-url">
      <i class="fa fa-plus-circle fa-minus-circle"></i>
    </a>
  </div>
  <div class="form-group custom-adsize">
    <label class="control-label col-md-3">
      <?=\Yii::t('creative', 'Material Size')?>：
    </label>
    <label class="control-label col-md-1 pr0">
      <?=\Yii::t('creative', 'Width')?>：
    </label>
    <div class="col-md-2">
      <input class="form-control adspace-width" type="text" value="" name="width[]" data-err="width-err">
      <div class="help-block text-error width-err "></div>
    </div>
    <label class="control-label col-md-1 pr0">
      <?=\Yii::t('creative', 'Height')?>：
    </label>
    <div class="col-md-2">
      <input class="form-control adspace-height" type="text" value="" name="height[]" data-err="height-err">
      <div class="help-block text-error height-err"></div>
    </div>
  </div>
  <div class="form-group">
    <label for="material-type" class="col-md-3 control-label">
      <?=\Yii::t('creative', 'Material Type')?>：
    </label>
    <div class="col-md-7">
      <select name="material_type[]" id="" class="form-control">
        <option value="JPG">JPG</option>
        <option value="PNG">PNG</option>
      </select>
    </div>
  </div>
</div>
<?php
  $uploadMaterialUrl = Url::to(['creative/upload-mobile-app-pic']);
  $videoPluginUrl = Yii::getAlias('@web').'/js/vendor/flowplayer/flowplayer.swf';
  $creativeVocation = $categories;
  //$creativeVocation = '{"汽车":["车讯行情","车辆养护","配件改装","其它"],"新闻":["军事","时政要闻","产经","科技","其它"],"财经":["股票","基金","理财","房产","保险","收藏","其它"],"数码":["电脑","手机","数码设备","软件","APP","其它"],"医疗":["健康养生","疾病治疗","整形美容","两性","其它"],"娱乐影音":["影视","音乐","图书","图片","星座","明星","游戏","宠物","休闲活动","其它"],"社交与网络服务":["婚恋交友","SNS","论坛","网络服务"],"教育":["幼教","应试","考研","培训","MBA","出国","自考","其它"],"家居家电":["家电","家具","装修","装饰","日常用品"],"体育":["足球","篮球","网球","户外","健身","器材","其它"],"旅行":["酒店和住宿","旅行社和服务","票务服务"],"女性":["时尚","美容","母婴"],"职业":["简历","招聘信息","其它"],"食品饮料":["美食","零食","饮料","烟酒","保健食品","其它"],"服饰鞋包":["服装","鞋靴","配饰","珠宝首饰","箱包","钟表","奢侈品","眼镜"],"工农业":["电子电工","机械设备","农林牧渔","化工及材料"],"生活和商务服务":["生活服务","商务服务"]}';
  $this->registerJs("VAM.setVar('UPLOAD_MATERIAL_URL','$uploadMaterialUrl');", View::POS_HEAD);
  $this->registerJs("VAM.setVar('VIDEO_PLUGIN_URL','$videoPluginUrl');", View::POS_HEAD);
  $this->registerJs("VAM.setVar('CREATIVE_VOCATION','$creativeVocation')", View::POS_HEAD);
  $this->registerJs("VAM.setVar('CLOSE_DIALOG_FLAG',true)", View::POS_HEAD);
?>
<script type="text/javascript" >
  requirejs(["<?= Yii::getAlias('@web/').Yii::$app->params['envDir'];?>/js/site.js"], function(common) {
    requirejs(["<?= Yii::getAlias('@web/').Yii::$app->params['envDir'];?>/js/creative/newAppCreative.js"]);
  });
</script>
